<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs">
<head>
<title>算术类型</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.21.2">
<link rel="shortcut icon" href="../../../common/favicon.ico">
<link rel="stylesheet" href="../../../common/ext.css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../../common/site_modules.css">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}#toc{display:none}.editsection{display:none}
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-css:7:15cea3ec788a65b5187d4018eed543bf */</style>

<script src="../../../common/startup_scripts.js"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"c/language/arithmetic_types","wgTitle":"c/language/arithmetic types","wgCurRevisionId":59305,"wgArticleId":7947,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Todo with reason"],"wgBreakFrames":false,"wgPageContentLanguage":"zh","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"zh","wgMonthNames":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgMonthNamesShort":["","1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],"wgRelevantPageName":"c/language/arithmetic_types","wgUserVariant":"zh","wgRestrictionEdit":[],"wgRestrictionMove":[]});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,
"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"zh","language":"zh","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"gadget-MathJax":1,"gadget-ColiruCompiler":1});;},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});;},{},{});
/* cache key: mwiki1-mwiki_zh_:resourceloader:filter:minify-js:7:258d7cd6aa9aa67dee25e01fb6a9e505 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-c {line-height: normal;}
.source-c li, .source-c pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for c
 * CSS class: source-c, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.c.source-c .de1, .c.source-c .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.c.source-c  {font-family:monospace;}
.c.source-c .imp {font-weight: bold; color: red;}
.c.source-c li, .c.source-c .li1 {font-weight: normal; vertical-align:top;}
.c.source-c .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.c.source-c .li2 {font-weight: bold; vertical-align:top;}
.c.source-c .kw1 {color: #0000dd;}
.c.source-c .kw2 {color: #0000ff;}
.c.source-c .kw3 {color: #0000dd;}
.c.source-c .kw4 {color: #0000ff;}
.c.source-c .co1 {color: #909090;}
.c.source-c .co2 {color: #339900;}
.c.source-c .coMULTI {color: #ff0000; font-style: italic;}
.c.source-c .es0 {color: #008000; font-weight: bold;}
.c.source-c .es1 {color: #008000; font-weight: bold;}
.c.source-c .es2 {color: #008000; font-weight: bold;}
.c.source-c .es3 {color: #008000; font-weight: bold;}
.c.source-c .es4 {color: #008000; font-weight: bold;}
.c.source-c .es5 {color: #008000; font-weight: bold;}
.c.source-c .br0 {color: #008000;}
.c.source-c .sy0 {color: #008000;}
.c.source-c .sy1 {color: #000080;}
.c.source-c .sy2 {color: #000040;}
.c.source-c .sy3 {color: #000040;}
.c.source-c .sy4 {color: #008080;}
.c.source-c .st0 {color: #008000;}
.c.source-c .nu0 {color: #000080;}
.c.source-c .nu6 {color:#000080;}
.c.source-c .nu8 {color:#000080;}
.c.source-c .nu12 {color:#000080;}
.c.source-c .nu16 {color:#000080;}
.c.source-c .nu17 {color:#000080;}
.c.source-c .nu18 {color:#000080;}
.c.source-c .nu19 {color:#000080;}
.c.source-c .ln-xtra, .c.source-c li.ln-xtra, .c.source-c div.ln-xtra {background-color: #ffc;}
.c.source-c span.xtra { display:block; }

/*]]>*/
</style><style type="text/css">/*<![CDATA[*/
.source-text {line-height: normal;}
.source-text li, .source-text pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for text
 * CSS class: source-text, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.text.source-text .de1, .text.source-text .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.text.source-text  {font-family:monospace;}
.text.source-text .imp {font-weight: bold; color: red;}
.text.source-text li, .text.source-text .li1 {font-weight: normal; vertical-align:top;}
.text.source-text .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.text.source-text .li2 {font-weight: bold; vertical-align:top;}
.text.source-text .ln-xtra, .text.source-text li.ln-xtra, .text.source-text div.ln-xtra {background-color: #ffc;}
.text.source-text span.xtra { display:block; }

/*]]>*/
</style><!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-c_language_arithmetic_types skin-cppreference2 action-view cpp-navbar">
        <!-- header -->
        <!-- /header -->
        <!-- content -->
<div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
<h1 id="firstHeading" class="firstHeading">算术类型</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">来自cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../../c.html" title="c">c</a>‎ | <a href="../language.html" title="c/language">language</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr"><div class="t-navbar" style=""><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../../c.html" title="c"> C</a><div class="t-navbar-menu"><div><div><table class="t-nv-begin" cellpadding="0" style="line-height:1.1em;">
<tr class="t-nv"><td colspan="5"> <a href="../language.html" title="c/language">语言</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../header.html" title="c/header">头文件</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../types.html" title="c/types">类型支持</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../program.html" title="c/program">程序工具</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../variadic.html" title="c/variadic">变参数函数支持</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../memory.html" title="c/memory">动态内存管理</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../error.html" title="c/error">错误处理</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../chrono.html" title="c/chrono">日期和时间工具</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../string.html" title="c/string">字符串库</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../algorithm.html" title="c/algorithm">算法</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../numeric.html" title="c/numeric">数值</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../io.html" title="c/io">输入/输出支持</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../locale.html" title="c/locale">本地化支持</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../thread.html" title="c/thread">线程支持</a> <span class="t-mark-rev t-since-c11">(C11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../atomic.html" title="c/atomic">原子操作</a> <span class="t-mark-rev t-since-c11">(C11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../experimental.html" title="c/experimental">技术规范</a> </td></tr>
</table></div><div></div></div></div></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="../language.html" title="c/language">C 语言</a></div><div class="t-navbar-sep"> </div><div class="t-navbar-head"><a href="basic_concepts.html" title="c/language/basic concepts">基本概念</a><div class="t-navbar-menu"><div><div style="display:inline-block">
<div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"> <a href="../comment.html" title="c/comment">注释</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="ascii.html" title="c/language/ascii">ASCII</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="escape.html" title="c/language/escape">转义序列</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="translation_phases.html" title="c/language/translation phases">翻译阶段</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="identifier.html" title="c/language/identifier">标识符</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="scope.html" title="c/language/scope">作用域</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="lifetime.html" title="c/language/lifetime">生存期</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="name_space.html" title="c/language/name space">查找与命名空间</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="type.html" title="c/language/types">类型</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="object.html" title="c/language/object">对象与对齐</a></td></tr>
<tr class="t-nv"><td colspan="5"> <strong class="selflink">算术类型</strong></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="main_function.html" title="c/language/main function"><code>main()</code> 函数</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="https://zh.cppreference.com/mwiki/index.php?title=c/language/as_if&amp;action=edit&amp;redlink=1" class="new" title="c/language/as if（页面不存在）">如同规则</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="behavior.html" title="c/language/behavior">未定义行为</a></td></tr>
<tr class="t-nv"><td colspan="5"> <a href="memory_model.html" title="c/language/memory model">内存模型与数据竞争</a></td></tr>
</table></div>
</div><div></div></div></div></div><div class="t-navbar-sep"> </div></div>
<p><small>（可参阅<a href="type.html" title="c/language/types">类型</a>，以获得类型系统综述，及 C 库提供的<a href="../types.html" title="c/types">类型相关工具列表</a>）</small>
</p>
 <table class="t-rev-begin">
<tr class="t-rev t-since-c99"><td>
<h3> <span class="mw-headline" id=".E5.B8.83.E5.B0.94.E7.B1.BB.E5.9E.8B">布尔类型</span></h3>
<dl><dd><ul><li> <span class="t-c"><span class="mw-geshi c source-c">_Bool</span></span> （亦可作为宏 <a href="../types/boolean.html" title="c/types/boolean">bool</a> 使用） - 类型，足以保有二个值之一： 1 与 0 （亦可作为宏 <a href="../types/boolean.html" title="c/types/boolean">true</a> 与 <a href="../types/boolean.html" title="c/types/boolean">false</a> 使用）。
</li></ul>
</dd></dl>
<p>注意，到 _Bool 的<a href="conversion.html" title="c/language/conversion">转换</a>与到其他整数类型的转换不同： <span class="t-c"><span class="mw-geshi c source-c"><span class="br0">(</span>bool<span class="br0">)</span><span class="nu16">0.5</span></span></span> 求值为 <span class="t-c"><span class="mw-geshi c source-c"><span class="nu0">1</span></span></span> ，然而 <span class="t-c"><span class="mw-geshi c source-c"><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span><span class="nu16">0.5</span></span></span> 求值为 <span class="t-c"><span class="mw-geshi c source-c">​<span class="nu0">0</span>​</span></span> 。
</p>
</td>
<td><span class="t-mark-rev t-since-c99">(C99 起)</span></td></tr>
</table>
<h3><span class="mw-headline" id=".E5.AD.97.E7.AC.A6.E7.B1.BB.E5.9E.8B">字符类型</span></h3>
<dl><dd><ul><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">char</span></span></span> - 用作有符号字符表示的类型。
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">char</span></span></span> - 用作无符号字符表示的类型。亦可用于查看<a href="object.html" title="c/language/object">对象表示</a>（无修饰内存）。
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">char</span></span></span> - 用于字符表示的类型。 与 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">char</span></span></span> 或 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">char</span></span></span> 等价（具体等价于哪个是实现定义的，并且可以通过编译器命令行开关控制），但 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">char</span></span></span> 是独立的类型，与 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">char</span></span></span> 及 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">char</span></span></span> 都不相同。
</li></ul>
</dd></dl>
<p>注意：标准亦定义了 <a href="typedef.html" title="c/language/typedef">typedef</a> 名 <a href="../string/wide.html" title="c/string/wide">wchar_t</a><span class="t-rev-inl t-since-c11"><span> 、 <a href="../string/multibyte.html" title="c/string/multibyte">char16_t</a> 及 <a href="../string/multibyte.html" title="c/string/multibyte">char32_t</a></span> <span><span class="t-mark-rev t-since-c11">(C11 起)</span></span></span> 以表示宽字符。
</p>
<h3><span class="mw-headline" id=".E6.95.B4.E6.95.B0.E7.B1.BB.E5.9E.8B">整数类型</span></h3>
<dl><dd><ul><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">short</span> <span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">short</span></span></span> ，可以用关键词 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span></span></span> ）
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">short</span> <span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">short</span></span></span> ）
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">int</span></span></span> ）
</li></ul>
<dl><dd> 这是平台的最理想整数类型，保证至少为 16 位。当前大多数平台使用 32 位（见后述的数据模型）。
</dd></dl>
<ul><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span></span></span> ）， <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">int</span></span></span> 的无符号对应者，实现模算术。适合位操作。
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span></span></span> ）
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span></span></span> ）
</li></ul>
</dd></dl>
 <table class="t-rev-begin">
<tr class="t-rev t-since-c99"><td>
<dl><dd><ul><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">long</span></span></span> ）
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span></span></span> ）
</li></ul>
</dd></dl>
</td>
<td><span class="t-mark-rev t-since-c99">(C99 起)</span></td></tr>
</table>
<p>注意：同所有类型指定符，允许任意顺序： <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span> 和 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">int</span> <span class="kw4">unsigned</span> <span class="kw4">long</span></span></span> 指名同一类型。
</p><p>下表总结所有可用的整数类型及其属性：
</p>
<table class="wikitable" style="text-align:center;">

<tr>
<th rowspan="2"> 类型指定符
</th>
<th rowspan="2"> 等价类型
</th>
<th colspan="5"> 数据模型中的位宽
</th></tr>
<tr>
<th> C 标准
</th>
<th> LP32
</th>
<th> ILP32
</th>
<th> LLP64
</th>
<th> LP64
</th></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">short</span></span></span></div>
</td>
<td rowspan="4"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">short</span> <span class="kw4">int</span></span></span>
</td>
<td rowspan="6"> 至少<br> <b>16</b>
</td>
<td rowspan="6"> <b>16</b>
</td>
<td rowspan="6"> <b>16</b>
</td>
<td rowspan="6"> <b>16</b>
</td>
<td rowspan="6"> <b>16</b>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">short</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">short</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">short</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">short</span></span></span></div>
</td>
<td rowspan="2"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">short</span> <span class="kw4">int</span></span></span>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">short</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">int</span></span></span></div>
</td>
<td rowspan="3"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">int</span></span></span>
</td>
<td rowspan="5"> 至少<br> <b>16</b>
</td>
<td rowspan="5"> <b>16</b>
</td>
<td rowspan="5"> <b>32</b>
</td>
<td rowspan="5"> <b>32</b>
</td>
<td rowspan="5"> <b>32</b>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span></span></span></div>
</td>
<td rowspan="2"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">int</span></span></span>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span></span></span></div>
</td>
<td rowspan="4"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">int</span></span></span>
</td>
<td rowspan="6"> 至少<br> <b>32</b>
</td>
<td rowspan="6"> <b>32</b>
</td>
<td rowspan="6"> <b>32</b>
</td>
<td rowspan="6"> <b>32</b>
</td>
<td rowspan="6"> <b>64</b>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">long</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span></span></span></div>
</td>
<td rowspan="2"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">long</span></span></span></div>
</td>
<td rowspan="4"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span> <br> <span class="t-mark-rev t-since-c99">(C99)</span>
</td>
<td rowspan="6"> 至少<br> <b>64</b>
</td>
<td rowspan="6"> <b>64</b>
</td>
<td rowspan="6"> <b>64</b>
</td>
<td rowspan="6"> <b>64</b>
</td>
<td rowspan="6"> <b>64</b>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">long</span> <span class="kw4">long</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">signed</span> <span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span></div>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span></span></span></div>
</td>
<td rowspan="2"> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span> <br> <span class="t-mark-rev t-since-c99">(C99)</span>
</td></tr>
<tr>
<td> <div style="text-align:left; width:auto; margin-left:auto; margin-right:auto;"><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">unsigned</span> <span class="kw4">long</span> <span class="kw4">long</span> <span class="kw4">int</span></span></span></div>
</td></tr></table>
<p>除了最小位数， C 标准还保证
</p>
<dl><dd><span class="t-c"><span class="mw-geshi c source-c"><span class="nu0">1</span> <span class="sy1">==</span> <span class="kw4">sizeof</span><span class="br0">(</span><span class="kw4">char</span><span class="br0">)</span> <span class="sy1">&lt;=</span> <span class="kw4">sizeof</span><span class="br0">(</span><span class="kw4">short</span><span class="br0">)</span> <span class="sy1">&lt;=</span> <span class="kw4">sizeof</span><span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="sy1">&lt;=</span> <span class="kw4">sizeof</span><span class="br0">(</span><span class="kw4">long</span><span class="br0">)</span> <span class="sy1">&lt;=</span> <span class="kw4">sizeof</span><span class="br0">(</span><span class="kw4">long</span> <span class="kw4">long</span><span class="br0">)</span></span></span> 。
</dd></dl>
<p>注意：这允许极端情形，如<a href="https://en.wikipedia.org/wiki/Byte" class="extiw" title="enwiki:Byte">字节</a>大小为 64 位，所有类型（包括 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">char</span></span></span> ）均为 64 位宽，而 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">sizeof</span></span></span> 对每个整数类型都返回 1 。
</p><p>注意：整数算术的定义对于有符号数和无符号数不同。见<a href="operator_arithmetic.html" title="c/language/operator arithmetic">算数运算符</a>，尤其是<a href="operator_arithmetic.html#.E6.BA.A2.E5.87.BA" title="c/language/operator arithmetic">整数溢出</a>。
</p>
<h4><span class="mw-headline" id=".E6.95.B0.E6.8D.AE.E6.A8.A1.E5.9E.8B">数据模型</span></h4>
<p>每个实现关于基础类型的大小选择被统称为<i>数据模型</i>。有四种广为接受的数据模型：
</p><p>32 位系统：
</p>
<dl><dd><ul><li><b>LP32</b> 或 <b>2/4/4</b> （ int 为 16 位， long 与指针为 32 位）
</li></ul>
<dl><dd><ul><li> Win16 API
</li></ul>
</dd></dl>
<ul><li><b>ILP32</b> 或 <b>4/4/4</b> （ int 、 long 及指针为 32 位）；
</li></ul>
<dl><dd><ul><li> Win32 API
</li><li> Unix 及类 Unix 系统（ Linux 、 Mac OS X ）
</li></ul>
</dd></dl>
</dd></dl>
<p>64 位系统：
</p>
<dl><dd><ul><li> <b>LLP64</b> 或 <b>4/4/8</b> （ int 及 long 为 32 位，指针为 64 位）
</li></ul>
<dl><dd><ul><li> Win64 API
</li></ul>
</dd></dl>
<ul><li> <b>LP64</b> 或 <b>4/8/8</b> （ int 为 32 位， long 及指针为 64 位）
</li></ul>
<dl><dd><ul><li> Unix 与类 Unix 系统（ Linux 、 Mac OS X ）
</li></ul>
</dd></dl>
</dd></dl>
<p>其他数据模型非常稀有。例如， <b>ILP64</b> （ <b>8/8/8</b> ： int 、 long 及指针均为 64 位）仅出现于某些早期 64 位 Unix 系统（例如 Unicos on Cray ）。
</p><p>注意从 C99 开始可从 <a href="../types/integer.html" title="c/types/integer">&lt;stdint.h&gt;</a> 中使用准确宽度的整数。
</p>
<h3><span class="mw-headline" id=".E5.AE.9E.E6.B5.AE.E7.82.B9.E7.B1.BB.E5.9E.8B">实浮点类型</span></h3>
<p>C 拥有三种表示实浮点值的类型：
</p>
<dl><dd><ul><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span></span></span> - 单精度浮点类型。若支持则匹配 IEEE-754 32 位浮点类型。
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span></span></span> - 双精度浮点类型。若支持则匹配 IEEE-754 64 位浮点类型。
</li><li><span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span></span></span> - 扩展精度浮点类型。若支持则匹配 IEEE-754 扩展浮点类型，否则匹配某些非标准扩展浮点类型，只要其精度高于 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span></span></span> 且范围至少与 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span></span></span> 相同，否则再匹配 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span></span></span> 类型。某些 x86 与 x86-64 实现使用 80 位x 87 浮点类型。
</li></ul>
</dd></dl>
<p>浮点类型可以支持特殊值：
</p>
<ul><li> <i>无穷大</i>（正与负），见 <a href="../numeric/math/INFINITY.html" title="c/numeric/math/INFINITY"><tt>INFINITY</tt></a>
</li><li> <i>负零</i>，<span class="t-c"><span class="mw-geshi c source-c"><span class="sy2">-</span><span class="nu16">0.0</span></span></span>。它与正零比较相等，但对于某些算术运算有意义（例如 <span class="t-c"><span class="mw-geshi c source-c"><span class="nu16">1.0</span><span class="sy2">/</span><span class="nu16">0.0</span> <span class="sy1">==</span> INFINITY</span></span> ，但 <span class="t-c"><span class="mw-geshi c source-c"><span class="nu16">1.0</span><span class="sy2">/-</span><span class="nu16">0.0</span> <span class="sy1">==</span> <span class="sy2">-</span>INFINITY</span></span> ）。
</li><li> <i>非数</i>（ NaN ），它与任何值比较不相等（包括其自身）。有多种位模式表示 NaN ，见 <span class="t-lc"><a href="../numeric/math/nan.html" title="c/numeric/math/nan">nan</a></span> 、  <a href="../numeric/math/NAN.html" title="c/numeric/math/NAN"><tt>NAN</tt></a> 。注意 C 对 NaN （ IEEE-754 所指定的）信号不作任何注意，并安静处理所有 NaN 。
</li></ul>
<p>实浮点数可用与<a href="operator_arithmetic.html" title="c/language/operator arithmetic">算术运算符</a> + - / *和来自 <a href="../numeric/math.html" title="c/numeric/math">math.h</a> 的大量数学函数一同使用。内建运算符和库函数都可能引发浮点异常，并以 <a href="../numeric/math/math_errhandling.html" title="c/numeric/math/math errhandling"><tt>math_errhandling</tt></a> 中描述的方式设置 <span class="t-lc"><a href="../error/errno.html" title="c/error/errno">errno</a></span> 。 
</p><p>浮点表达式可拥有大于其类型所指示的范围和精度，见 <span class="t-lc"><a href="../types/limits/FLT_EVAL_METHOD.html" title="c/types/limits/FLT EVAL METHOD">FLT_EVAL_METHOD</a></span> 。<a href="operator_assignment.html" title="c/language/operator assignment">赋值</a>、 <a href="return.html" title="c/language/return">return</a> 和<a href="cast.html" title="c/language/cast">转型</a>强制将范围和精度变成声明类型所关联者。
</p><p>浮点表达式亦可被<i>缩略</i>，即仿佛中间值拥有无限范围和精度一般计算，见 <a href="../preprocessor/impl.html#.E6.A0.87.E5.87.86_pragma" title="c/preprocessor/impl">#pragma STDC FP_CONTRACT</a>。
</p><p>一些浮点数上的运算会受到<a href="../numeric/fenv.html" title="c/numeric/fenv">浮点环境</a>的影响，或修改它（最值得注意的是舍入方向）
</p><p>实浮点类型与整数、复数和虚数类型间的<a href="conversion.html" title="c/language/conversion">隐式转换</a>有定义。
</p><p>附加细节、极限和浮点类型属性见<a href="../types/limits.html#.E6.B5.AE.E7.82.B9.E7.B1.BB.E5.9E.8B.E6.9E.81.E9.99.90" title="c/types/limits">浮点类型极限</a>与 <a href="../numeric/math.html" title="c/numeric/math">math.h 库</a>。
</p>
 <table class="t-rev-begin">
<tr class="t-rev t-since-c99"><td>
<h3> <span class="mw-headline" id=".E5.A4.8D.E6.B5.AE.E7.82.B9.E7.B1.BB.E5.9E.8B">复浮点类型</span></h3>
<p>复浮点类型模仿数学的<a href="https://en.wikipedia.org/wiki/Complex_number" class="extiw" title="enwiki:Complex number">复数</a>，即可以写成一个实数与一个实数乘虚数单位的和的数： <span class="texhtml" style="white-space: nowrap;">a + bi</span>
</p><p>三种复数类型是
</p>
<dl><dd><ul><li> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span> _Complex</span></span> （亦可用作<span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a></span></span>，若包含了 <a href="../numeric/complex.html" title="c/numeric/complex">&lt;complex.h&gt;</a> ）
</li><li> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> _Complex</span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a></span></span>，若包含了 <a href="../numeric/complex.html" title="c/numeric/complex">&lt;complex.h&gt;</a> ）
</li><li> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> _Complex</span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a></span></span> ，若包含了 <a href="../numeric/complex.html" title="c/numeric/complex">&lt;complex.h&gt;</a> ）
</li></ul>
</dd></dl>
<p>注意：同所有类型指定符，允许任意顺序： <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a></span></span> 、 <span class="t-c"><span class="mw-geshi c source-c"><a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a> <span class="kw4">long</span> <span class="kw4">double</span></span></span> ，甚至 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a> <span class="kw4">long</span></span></span> 都指名同一类型。
</p>
<div class="t-example"><div class="t-example-live-link"><div class="coliru-btn coliru-btn-run-init">运行此代码</div></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="c source-c"><pre class="de1"><span class="co2">#include &lt;complex.h&gt;</span>
<span class="co2">#include &lt;stdio.h&gt;</span>
<span class="kw4">int</span> main<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a> z <span class="sy1">=</span> <span class="nu0">1</span> <span class="sy2">+</span> <span class="nu0">2</span><span class="sy2">*</span>I<span class="sy4">;</span>
    z <span class="sy1">=</span> <span class="nu0">1</span><span class="sy2">/</span>z<span class="sy4">;</span>
    <a href="../io/fprintf.html"><span class="kw851">printf</span></a><span class="br0">(</span><span class="st0">"1/(1.0+2.0i) = %.1f%+.1fi<span class="es1">\n</span>"</span>, <a href="../numeric/complex/creal.html"><span class="kw754">creal</span></a><span class="br0">(</span>z<span class="br0">)</span>, <a href="../numeric/complex/cimag.html"><span class="kw751">cimag</span></a><span class="br0">(</span>z<span class="br0">)</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>输出：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="text source-text"><pre class="de1">1/(1.0+2.0i) = 0.2-0.4i</pre></div></div> 
</div>
 <table class="t-rev-begin">
<tr class="t-rev t-since-c11"><td>
<p>若实现定义了宏常量 <code>__STDC_NO_COMPLEX__</code><span class="t-mark-rev t-since-c11">(C11)</span>，则不提供复数类型（还有库头文件 <code>&lt;complex.h&gt;</code> ）。
</p>
</td>
<td><span class="t-mark-rev t-since-c11">(C11 起)</span></td></tr>
</table>
<p>每个复数类型与拥有二个对应实数类型（ <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span></span></span> 之于 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a></span></span> ，<span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span></span></span> 之于 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a></span></span> ， <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span></span></span> 之于 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a></span></span> ）元素的<a href="array.html" title="c/language/array">数组</a>相同的<a href="object.html" title="c/language/object">对象表示</a>和<a href="object.html" title="c/language/object">对齐要求</a>。数组第一元素保有实部，而第二个元素保有虚部。
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="c source-c"><pre class="de1"><span class="kw4">float</span> a<span class="br0">[</span><span class="nu0">4</span><span class="br0">]</span> <span class="sy1">=</span> <span class="br0">{</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span>, <span class="nu0">4</span><span class="br0">}</span><span class="sy4">;</span>
<span class="kw4">float</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a> z1, z2<span class="sy4">;</span>
<a href="../string/byte/memcpy.html"><span class="kw572">memcpy</span></a><span class="br0">(</span><span class="sy3">&amp;</span>z1, a, <span class="kw4">sizeof</span> z1<span class="br0">)</span><span class="sy4">;</span> <span class="co1">// z1 成为 1.0 + 2.0i</span>
<a href="../string/byte/memcpy.html"><span class="kw572">memcpy</span></a><span class="br0">(</span><span class="sy3">&amp;</span>z2, a<span class="sy2">+</span><span class="nu0">2</span>, <span class="kw4">sizeof</span> z2<span class="br0">)</span><span class="sy4">;</span> <span class="co1">// z2 成为 3.0 + 4.0i</span></pre></div></div>
<p>复数可用于<a href="operator_arithmetic.html" title="c/language/operator arithmetic">算术运算符</a> + - * 和 / ， <a href="../numeric/complex.html" title="c/numeric/complex">complex.h</a> 中为复数定义许多数学函数。内建运算符和库函数都可能引发浮点异常，并按 <a href="../numeric/math/math_errhandling.html" title="c/numeric/math/math errhandling"><tt>math_errhandling</tt></a> 中描述的方式设置 <span class="t-lc"><a href="../error/errno.html" title="c/error/errno">errno</a></span> 。
</p><p>复数类型中不定义自增和自减。
</p><p>复数类型中不定义关系运算符（没有“小于”的记号）。
</p>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style=""><tr><td class="mbox-empty-cell"></td><td class="mbox-text" style="">本节未完成<br>原因：审阅其他操作、链接库 </td></tr></table><a href="conversion.html" title="c/language/conversion">隐式转换</a>定义于复数类型和其他算术类型。
<p>为支持复数算术的一个无限模型， C 认可任何至少有一个无限部分的复数值为无穷大，即使另一部分是 NaN ，保证所有运算符和函数忠实于无穷大的基本属性，并提供 <span class="t-lc"><a href="../numeric/complex/cproj.html" title="c/numeric/complex/cproj">cproj</a></span> 以映射所有无穷大到标准的一（准确规则见<a href="operator_arithmetic.html" title="c/language/operator arithmetic">算术运算符</a>）。
</p>
<div class="t-example"><div class="t-example-live-link"><div class="coliru-btn coliru-btn-run-init">运行此代码</div></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="c source-c"><pre class="de1"><span class="co2">#include &lt;stdio.h&gt;</span>
<span class="co2">#include &lt;complex.h&gt;</span>
<span class="co2">#include &lt;math.h&gt;</span>
<span class="kw4">int</span> main<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span>
<span class="br0">{</span>
   <span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a> z <span class="sy1">=</span> <span class="br0">(</span><span class="nu0">1</span> <span class="sy2">+</span> <span class="nu0">0</span><span class="sy2">*</span>I<span class="br0">)</span> <span class="sy2">*</span> <span class="br0">(</span>INFINITY <span class="sy2">+</span> I<span class="sy2">*</span>INFINITY<span class="br0">)</span><span class="sy4">;</span>
<span class="co1">// 教科书公式会给出</span>
<span class="co1">// (1+i0)(∞+i∞) ⇒ (1×∞ – 0×∞) + i(0×∞+1×∞) ⇒ NaN + I*NaN</span>
<span class="co1">// 但 C 给出复无穷大</span>
   <a href="../io/fprintf.html"><span class="kw851">printf</span></a><span class="br0">(</span><span class="st0">"%f + i*%f<span class="es1">\n</span>"</span>, <a href="../numeric/complex/creal.html"><span class="kw754">creal</span></a><span class="br0">(</span>z<span class="br0">)</span>, <a href="../numeric/complex/cimag.html"><span class="kw751">cimag</span></a><span class="br0">(</span>z<span class="br0">)</span><span class="br0">)</span><span class="sy4">;</span>
 
<span class="co1">// 教科书方程会给出</span>
<span class="co1">// cexp(∞+iNaN) ⇒ exp(∞)×(cis(NaN)) ⇒ NaN + I*NaN</span>
<span class="co1">// 但 C 给出±∞+i*nan</span>
   <span class="kw4">double</span> <a href="../numeric/complex/complex.html"><span class="kw743">complex</span></a> y <span class="sy1">=</span> <a href="../numeric/complex/cexp.html"><span class="kw769">cexp</span></a><span class="br0">(</span>INFINITY <span class="sy2">+</span> I<span class="sy2">*</span>NAN<span class="br0">)</span><span class="sy4">;</span>
   <a href="../io/fprintf.html"><span class="kw851">printf</span></a><span class="br0">(</span><span class="st0">"%f + i*%f<span class="es1">\n</span>"</span>, <a href="../numeric/complex/creal.html"><span class="kw754">creal</span></a><span class="br0">(</span>y<span class="br0">)</span>, <a href="../numeric/complex/cimag.html"><span class="kw751">cimag</span></a><span class="br0">(</span>y<span class="br0">)</span><span class="br0">)</span><span class="sy4">;</span>
 
<span class="br0">}</span></pre></div></div>
<p>可能的输出：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="text source-text"><pre class="de1">inf + i*inf 
inf + i*nan</pre></div></div> 
</div>
<p>C 也会处理多重无穷大，以在可能的地方保留方向信息，不管笛卡尔表示的固有限制：
</p><p>实无穷大乘虚数单位，会给出对应符号的虚无穷大： i × ∞ = i∞ 。同理， i × (∞ – i∞) = ∞ + i∞ 指示合理的象限。
</p>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style=""><tr><td class="mbox-empty-cell"></td><td class="mbox-text" style="">本节未完成<br>原因：遣词 </td></tr></table>
<h3> <span class="mw-headline" id=".E8.99.9A.E6.B5.AE.E7.82.B9.E7.B1.BB.E5.9E.8B">虚浮点类型</span></h3>
<p>虚浮点类型模仿数学的<a href="https://en.wikipedia.org/wiki/Imaginary_number" class="extiw" title="enwiki:Imaginary number">虚数</a>，即可以写成实数乘虚数单位的数： <span class="texhtml" style="white-space: nowrap;">bi</span>
三种虚数类型是
</p>
<dl><dd><ul><li> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span> _Imaginary</span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a></span></span> ，若包含了 <a href="../numeric/complex.html" title="c/numeric/complex">&lt;complex.h&gt;</a> ）
</li><li> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> _Imaginary</span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a></span></span> ，若包含了 <a href="../numeric/complex.html" title="c/numeric/complex">&lt;complex.h&gt;</a> ）
</li><li> <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> _Imaginary</span></span> （亦可用作 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a></span></span> ，若包含了 <a href="../numeric/complex.html" title="c/numeric/complex">&lt;complex.h&gt;</a> ）
</li></ul>
</dd></dl>
<p>注意：同所有类型指定符，允许任意顺序： <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a></span></span> 、 <span class="t-c"><span class="mw-geshi c source-c"><a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a> <span class="kw4">long</span> <span class="kw4">double</span></span></span> ，甚至 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a> <span class="kw4">long</span></span></span> 都指名同一类型。
</p>
<div class="t-example"><div class="t-example-live-link"><div class="coliru-btn coliru-btn-run-init">运行此代码</div></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="c source-c"><pre class="de1"><span class="co2">#include &lt;complex.h&gt;</span>
<span class="co2">#include &lt;stdio.h&gt;</span>
<span class="kw4">int</span> main<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw4">double</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a> z <span class="sy1">=</span> <span class="nu0">3</span><span class="sy2">*</span>I<span class="sy4">;</span>
    z <span class="sy1">=</span> <span class="nu0">1</span><span class="sy2">/</span>z<span class="sy4">;</span>
    <a href="../io/fprintf.html"><span class="kw851">printf</span></a><span class="br0">(</span><span class="st0">"1/(3.0i) = %+.1fi<span class="es1">\n</span>"</span>, <a href="../numeric/complex/cimag.html"><span class="kw751">cimag</span></a><span class="br0">(</span>z<span class="br0">)</span><span class="br0">)</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>输出：
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="text source-text"><pre class="de1">1/(3.0i) = -0.3i</pre></div></div> 
</div>
 <table class="t-rev-begin">
<tr class="t-rev t-since-c99 t-until-c11"><td>
<p>推荐编译器定义 <span class="t-c"><span class="mw-geshi c source-c">__STDC_IEC_559_COMPLEX__</span></span> ，但不要求支持虚数。 POSIX 推荐检查是否定义宏 <span class="t-lc"><a href="../numeric/complex/Imaginary_I.html" title="c/numeric/complex/Imaginary I">_Imaginary_I</a></span> 以鉴别是否支持虚数。
</p>
</td>
<td><span class="t-mark-rev t-since-c99">(C99 起)</span><br><span class="t-mark-rev t-until-c11">(C11 前)</span></td></tr>
<tr class="t-rev t-since-c11"><td>
<p>若定义 <span class="t-c"><span class="mw-geshi c source-c">__STDC_IEC_559_COMPLEX__</span></span> ，则支持虚数。
</p>
</td>
<td><span class="t-mark-rev t-since-c11">(C11 起)</span></td></tr>
</table>
<p>三种虚数类型各拥有与其<i>对应实数类型</i>（ <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span></span></span> 之于 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">float</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a></span></span> ， <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span></span></span> 之于 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">double</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a></span></span> ， <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span></span></span> 之于 <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">long</span> <span class="kw4">double</span> <a href="../numeric/complex/imaginary.html"><span class="kw745">imaginary</span></a></span></span> ）相同的<a href="object.html" title="c/language/object">对象表示</a>和<a href="object.html" title="c/language/object">对齐要求</a>。 
</p><p>注意：尽管如此，虚数类型是独立的，且与其对应实数类型<a href="type.html#.E5.85.BC.E5.AE.B9.E7.B1.BB.E5.9E.8B" title="c/language/types">不兼容</a>，这禁止别名使用。
</p><p>虚数可用于 <a href="operator_arithmetic.html" title="c/language/operator arithmetic">算术运算符</a> + - * 及 / ，并且可与复数和实数混用。 <a href="../numeric/complex.html" title="c/numeric/complex">complex.h</a> 中为虚数类型定义多个数学函数。内建运算符和库函数都可能引发浮点异常，并按描述于 <a href="../numeric/math/math_errhandling.html" title="c/numeric/math/math errhandling"><tt>math_errhandling</tt></a> 的方式设置 <span class="t-lc"><a href="../error/errno.html" title="c/error/errno">errno</a></span> 。
</p><p>自增和自减不定义于虚数类型。
</p>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style=""><tr><td class="mbox-empty-cell"></td><td class="mbox-text" style="">本节未完成<br>原因：审阅其他操作、链接库 </td></tr></table><a href="conversion.html" title="c/language/conversion">隐式转换</a>定义于虚数类型和其他算术类型之间。
<p>虚数类型零通过自然记号 <span class="t-c"><span class="mw-geshi c source-c">x <span class="sy2">+</span> I<span class="sy2">*</span>y</span></span> （其中 <span class="t-lc">I</span> 定义为 <span class="t-lc"><a href="../numeric/complex/Imaginary_I.html" title="c/numeric/complex/Imaginary I">_Imaginary_I</a></span> ）表示所有复数成为可能。若无虚数类型，则无法自然地创建一些特殊复数值。例如，若 <span class="t-lc">I</span> 被定义为 <span class="t-lc"><a href="../numeric/complex/Complex_I.html" title="c/numeric/complex/Complex I">_Complex_I</a></span> ，则书写 <span class="t-c"><span class="mw-geshi c source-c"><span class="nu16">0.0</span> <span class="sy2">+</span> I<span class="sy2">*</span>INFINITY</span></span> 会给出有 NaN 实部的结果，而必须用 <span class="t-c"><span class="mw-geshi c source-c"><a href="../numeric/complex/CMPLX.html"><span class="kw748">CMPLX</span></a><span class="br0">(</span><span class="nu16">0.0</span>, INFINITY<span class="br0">)</span></span></span> 替代之。拥有负零虚部的数亦然，这对于使用存在分支的库函数有意义，例如 <span class="t-lc"><a href="../numeric/complex/csqrt.html" title="c/numeric/complex/csqrt">csqrt</a></span> ：若 <span class="t-lc">I</span> 定义为 <span class="t-lc"><a href="../numeric/complex/Complex_I.html" title="c/numeric/complex/Complex I">_Complex_I</a></span>，则 <span class="t-c"><span class="mw-geshi c source-c"><span class="nu16">1.0</span> <span class="sy2">-</span> <span class="nu16">0.0</span><span class="sy2">*</span>I</span></span> 结果有正零的虚部，并要求用 <span class="t-lc"><a href="../numeric/complex/CMPLX.html" title="c/numeric/complex/CMPLX">CMPLX</a></span> 或 <span class="t-lc"><a href="../numeric/complex/conj.html" title="c/numeric/complex/conj">conj</a></span> 获得负零虚部。
</p><p>虚数类型亦会简化实现：复数乘虚数可以直接实现为二次乘法，若支持虚数，而非四次乘法和二次加法。
</p>
</td>
<td><span class="t-mark-rev t-since-c99">(C99 起)</span></td></tr>
</table>
<h3><span class="mw-headline" id=".E5.85.B3.E9.94.AE.E8.AF.8D">关键词</span></h3>
<p><a href="../keyword/char.html" title="c/keyword/char"><tt>char</tt></a>, 
<a href="../keyword/int.html" title="c/keyword/int"><tt>int</tt></a>,
<a href="../keyword/short.html" title="c/keyword/short"><tt>short</tt></a>,
<a href="../keyword/long.html" title="c/keyword/long"><tt>long</tt></a>,
<a href="../keyword/signed.html" title="c/keyword/signed"><tt>signed</tt></a>,
<a href="../keyword/unsigned.html" title="c/keyword/unsigned"><tt>unsigned</tt></a>,
<a href="../keyword/float.html" title="c/keyword/float"><tt>float</tt></a>,
<a href="../keyword/double.html" title="c/keyword/double"><tt>double</tt></a>.
<a href="../keyword/_Bool.html" title="c/keyword/ Bool"><tt>_Bool</tt></a>,
<a href="../keyword/_Complex.html" title="c/keyword/ Complex"><tt>_Complex</tt></a>,
<a href="../keyword/_Imaginary.html" title="c/keyword/ Imaginary"><tt>_Imaginary</tt></a>
</p>
<h3><span class="mw-headline" id=".E5.80.BC.E5.9F.9F">值域</span></h3>
<p>下表提供常用数值表示极限的参考。因为 C 标准允许任何有符号整数表示，该表给出两种最小保证要求（对应<a href="https://en.wikipedia.org/wiki/One%27s_complement" class="extiw" title="enwiki:One's complement">反码</a>或<a href="https://en.wikipedia.org/wiki/Signed_number_representations#Sign-and-magnitude_method" class="extiw" title="enwiki:Signed number representations">原码</a>）和最常用实现<a href="https://en.wikipedia.org/wiki/Two%27s_complement" class="extiw" title="enwiki:Two's complement">补码</a>的极限。尽管所有通行数据模型（含 ILP32 、 LP32 、 LP64 、 LLP64 全体）都采用补码表示。
</p>
<table class="wikitable" style="text-align:center;">

<tr>
<th rowspan="2"> 类型
</th>
<th rowspan="2"> 位大小
</th>
<th rowspan="2"> 格式
</th>
<th colspan="2"> 值域
</th></tr>
<tr>
<th> 粗略
</th>
<th> 准确
</th></tr>
<tr>
<th rowspan="3"> 字符
</th>
<td rowspan="3"> 8
</td>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（反码）</span>
</td>
<td colspan="2"> <b>-127</b> 到 <b>127</b>
</td></tr>
<tr>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（补码）</span>
</td>
<td colspan="2"> <b>-128</b> 到 <b>127</b>
</td></tr>
<tr>
<td> 无符号
</td>
<td colspan="2"> <b>0</b> 到 <b>255</b>
</td></tr>

<tr>
<th rowspan="9"> 整数
</th>
<td rowspan="3"> 16
</td>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（反码）</span>
</td>
<td rowspan="2"> <b>± 3.27 · 10<sup>4</sup></b>
</td>
<td> <b>-32767</b> 到 <b>32767</b>
</td></tr>
<tr>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（补码）</span>
</td>
<td> <b>-32768</b> 到 <b>32767</b>
</td></tr>
<tr>
<td> 无符号
</td>
<td> <b>0</b> 到 <b>6.55 · 10<sup>4</sup></b>
</td>
<td> <b>0</b> 到 <b>65535</b>
</td></tr>
<tr>
<td rowspan="3"> 32
</td>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（反码）</span>
</td>
<td rowspan="2"> <b>± 2.14 · 10<sup>9</sup></b>
</td>
<td> <b>-2,147,483,647</b> 到 <b>2,147,483,647</b>
</td></tr>
<tr>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（补码）</span>
</td>
<td> <b>-2,147,483,648</b> 到 <b>2,147,483,647</b>
</td></tr>
<tr>
<td> 无符号
</td>
<td> <b>0</b> 到 <b>4.29 · 10<sup>9</sup></b>
</td>
<td> <b>0</b> 到 <b>4,294,967,295</b>
</td></tr>
<tr>
<td rowspan="3"> 64
</td>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（反码）</span>
</td>
<td rowspan="2"> <b>± 9.22 · 10<sup>18</sup></b>
</td>
<td> <b>-9,223,372,036,854,775,807</b> 到 <b>9,223,372,036,854,775,807</b>
</td></tr>
<tr>
<td> 有符号<span style="font-size:0.7em; line-height:130%">（补码）</span>
</td>
<td> <b>-9,223,372,036,854,775,808</b> 到 <b>9,223,372,036,854,775,807</b>
</td></tr>
<tr>
<td> 无符号
</td>
<td> <b>0</b> 到 <b>1.84 · 10<sup>19</sup></b>
</td>
<td> <b>0</b> 到 <b>18,446,744,073,709,551,615</b>
</td></tr>
<tr>
<th rowspan="2"> 浮点数
</th>
<td> 32
</td>
<td> <a href="https://en.wikipedia.org/wiki/IEEE-754" class="extiw" title="enwiki:IEEE-754">IEEE-754</a>
</td>
<td><div>
<ul><li>最小非正规：<br><b>± 1.401,298,4 · 10<sup>-45</sup></b>
</li><li>最小正规：<br><b>± 1.175,494,3 · 10<sup>-38</sup></b>
</li><li>最大：<br><b>± 3.402,823,4 · 10<sup>38</sup></b>
</li></ul>
</div>
</td>
<td><div>
<ul><li>最小非正规：<br><b>±0x1p-149</b>
</li><li>最小正规：<br><b>±0x1p-126</b>
</li><li>最大：<br><b>±0x1.fffffep+127</b>
</li></ul>
</div>
</td></tr>
<tr>
<td> 64
</td>
<td> <a href="https://en.wikipedia.org/wiki/IEEE-754" class="extiw" title="enwiki:IEEE-754">IEEE-754</a>
</td>
<td> <div>
<ul><li>最小非正规：<br><b>± 4.940,656,458,412 · 10<sup>-324</sup></b>
</li><li>最小正规：<br><b>± 2.225,073,858,507,201,4 · 10<sup>-308</sup></b>
</li><li>最大：<br><b>± 1.797,693,134,862,315,7 · 10<sup>308</sup></b>
</li></ul>
</div>
</td>
<td> <div>
<ul><li>最小非正规：<br><b>±0x1p-1074</b>
</li><li>最小正规：<br><b>±0x1p-1022</b>
</li><li>最大：<br><b>±0x1.fffffffffffffp+1023</b>
</li></ul>
</div>
</td></tr></table>
<p>注意：实际（与保证最小值相对）的范围可在库头文件 <a href="../types/limits.html" title="c/types/limits">&lt;limits.h&gt; 和 &lt;float.h&gt;</a> 中获得
</p>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>
<table class="t-dsc-begin">

</table>

<!-- 
NewPP limit report
Preprocessor visited node count: 5692/1000000
Preprocessor generated node count: 12197/1000000
Post‐expand include size: 79316/2097152 bytes
Template argument size: 34767/2097152 bytes
Highest expansion depth: 20/40
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_zh_:pcache:idhash:7947-0!*!0!!zh!*!zh!* and timestamp 20200217023451 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    来自“<a href="https://zh.cppreference.com/mwiki/index.php?title=c/language/arithmetic_types&amp;oldid=59305">https://zh.cppreference.com/mwiki/index.php?title=c/language/arithmetic_types&amp;oldid=59305</a>”                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        <div id="cpp-footer-base" class="noprint">
            <div id="footer">
                        <div id="cpp-navigation">
            <h5>导航</h5>
            <ul><li><a href="https://zh.cppreference.com/w/c/language/arithmetic_types">Online version</a></li><li>Offline version retrieved 2020-03-14 18:00.</li></ul></div>
                        <ul id="footer-info">
                                    <li id="footer-info-lastmod"> 本页面最后修改于2019年1月10日 (星期四) 04:46。</li>
                                    <li id="footer-info-viewcount">此页面已被浏览过5,586次。</li>
                            </ul>
                    </div>
        </div>
        <!-- /footer -->
        <script>if(window.mw){
mw.loader.state({"site":"loading","user":"missing","user.groups":"ready"});
}</script>
<script src="../../../common/skin_scripts.js"></script>
<script>if(window.mw){
mw.loader.load(["mediawiki.action.view.postEdit","mediawiki.user","mediawiki.page.ready","mediawiki.searchSuggest","mediawiki.hidpi","ext.gadget.MathJax","ext.gadget.ColiruCompiler"], null, true);
}</script>
<script src="../../../common/site_scripts.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2828341-1']);
_gaq.push(['_setDomainName', 'cppreference.com']);
_gaq.push(['_trackPageview']);
</script><!-- Served in 2.644 secs. -->
	</body>
<!-- Cached 20200217023451 -->
</html>